<?php
namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Session;
use app\index\model\User;

class Common extends Controller
{
    public function _initialize()
    {
        if (!checkRiskString()) {
            if (Request::instance()->isPost()) {
                abort(200, json_encode([
                    'code' => 0,
                    'msg'  => '输入存在危险字符,已被系统拦截'
                ]));
            } else {
                $this->error('输入存在危险字符,已被系统拦截');
            }
        }
        if (Request::instance()->controller() != 'Login' && !Session::get('cps_user_id')) {
            $this->redirect('login/index');
        } elseif (Request::instance()->controller() != 'Login' && !Session::get('cps_user_mobile')) {
            $this->redirect('login/bind_mobile');
        } elseif (in_array(Session::get('cps_user_status'), [2, 3])) {
            if (!in_array(Request::instance()->controller(), ['Common', 'Login']) && Request::instance()->action() != 'wait') {
                $this->redirect('common/wait');
            }
        }
    }

    //待审核状态和审核拒绝状态显示页面
    public function wait()
    {
        $info = [];
        if (Session::get('cps_user_status') == 3) {
            $userModel = new User();
            $info = $userModel->getInfoByField('id', Session::get('cps_user_id'), 'audit_info');
        }
        return view('common/wait', [
            'info'        => $info['audit_info']
        ]);
    }

    //空操作
    public function _empty()
    {
        return view('common/error', [
            'message' => '对不起，系统出现问题！'
        ]);
    }
}
